// 语言包
var chi = require('../../utils/Chinese.js')
var eng = require("../../utils/English.js")
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language: '',
    // 语言包对象
    content: '',
    add:true,//提示收货地址是否隐藏
    add_show:false,//是否显示收货地址
    posi:"",
    list: [{ id: "0", url: "../../img/tuijian_03.jpg", name: "焦糖味糖浆 意大利原装", price: 127, capacity: '1000ml', number: "1" }, { id: "0", url: "../../img/tuijian_03.jpg", name: "焦糖味糖浆 意大利原装", price: 127, capacity: '10000ml', number: "1" }],
    num: "",
    free_price: 0,
    free: "满88元免邮",
    invoice:true,//是否开具发票 true:开、false:不开 默认false
    invoice_true:"个人发票",
    common:"",
  },


  on: function () {
    let that = this
    var len = that.data.list.length
    var common = ""
    // 初始化data
    that.setData({
      language: app.data.language,
      posi:app.data.posi,
      add_show:app.data.add_show,
      invoice_true:app.data.invoice_true,
    })
    var lastLanuage = that.data.language
    if (lastLanuage == 'zh_CN') {
      common = '共'+ len + '件'
      that.setData({
        content: chi.content,
        common:common
      })
      wx.setNavigationBarTitle({
        title: '订单信息'
      })
    } else if (lastLanuage == 'zh_EN') {
      common = len + 'piece'
      that.setData({
        content: eng.content,
        common:common
      })
      // 修改导航标题
      wx.setNavigationBarTitle({
        title: 'Order Information'
      })
    }
    if(app.data.add_show == true){
      that.setData({
        add:false,
        add_show:true
      })
    }

  },
  // 页面跳转
  address:function(){
    wx.navigateTo({
      url: '../address/address',
    })
  },
  // 发票
  invoice:function(){
    wx.navigateTo({
      url: '../invoice/invoice',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    that.on()
    var list = that.data.list
    var num =0
    for (let i = 0; i < list.length; i++) {
      var price =parseInt(list[i].price)
      num += price
    }
    that.setData({
      num:num
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    that.on()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})